package oop.core.view;
/**
 * This represents the terminal of the game
 * which shows conversational dialogues 
 * and damge statistics
 */
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.TextArea;
import java.math.BigInteger;
import java.util.Random;

public class Terminal extends TextArea {

	private final Point TERMINAL_LOCATION;
	private final Dimension TERMINAL_SIZE;
	
	public Terminal()
	{
		this(0,600,600,200);
	}
	
	public Terminal(int x, int y, int width, int height)
	{
		this(new Point(x,y), new Dimension(width,height));
	}
	
	public Terminal(Point location, Dimension size)
	{
		TERMINAL_LOCATION = location;
		TERMINAL_SIZE = size;

		setLocation(TERMINAL_LOCATION);
		setSize(TERMINAL_SIZE);
		setBackground(Color.BLACK);
		setForeground(Color.GREEN);
		setFocusable(false);
	}
	
	/**
	 * print out random 0000111
	 */
	public void printMatrix()
	{
		Random random = new Random();
		byte[] bytes = new byte[12];
		random.nextBytes(bytes);
		String byteText = getBits(bytes);
		if(byteText.charAt(0) == '-')
			byteText = byteText.substring(1);
		appendln(byteText);
	}
	
	public void appendln(String text)
	{
		super.append(text + "\n");
	}
	
	private String getBits(byte[] bytes)
	{
		BigInteger big = new BigInteger(bytes);
		String bits = big.toString(2);
		return bits;
	}

}
